#include "read.h"
#include <stdio.h>

#include    <sys/types.h>    /* basic system data types */
#include    <sys/socket.h>    /* basic socket definitions */
#include    <sys/time.h>    /* timeval{} for select() */
#include    <time.h>        /* timespec{} for pselect() */
#include    <netinet/in.h>    /* sockaddr_in{} and other Internet defns */
#include    <arpa/inet.h>    /* inet(3) functions */
#include    <errno.h>
#include    <fcntl.h>        /* for nonblocking */
#include    <netdb.h>
#include    <signal.h>
#include    <stdio.h>
#include    <stdlib.h>
#include    <string.h>
#include    <sys/stat.h>    /* for S_xxx file mode constants */
#include    <sys/uio.h>        /* for iovec{} and readv/writev */
#include    <unistd.h>
#include    <sys/wait.h>
#include    <sys/un.h>        /* for Unix domain sockets */

void read_data(int sock)
{
    int n;
    char buf[1024] = {0};

    printf("block in read!");

    while(1) {
        if (read(sock, buf, 1024) < 0) {        //error
            printf("\nread error!!!\n");
        }
        if (read(sock, buf, 1024) == 0) {       //blocking
            continue;
        }
        if (read(sock, buf, 1024) > 0) {
            fprintf(stdout, "\n1K read for \n");
            printf("%s", buf);
        }
    }

}
